package bianlifeng;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-9-1下午 05:19
 */
public class Test3 {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int n = sc.nextInt();
        final String[] split = str.split(",");
        int[] arr = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            arr[i] = Integer.parseInt(split[i]);
        }
        //1 1 2 2 3 7
        //1 2 3 4 5 7
        sortArray(arr);
        int res = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] <= n) {
                n -= arr[i];
                res++;
            }
        }
        System.out.println(res);
    }

    public static int[] sortArray(int[] nums) {
        quicksort(nums, 0, nums.length - 1);
        return nums;
    }

    public static void quicksort(int[] nums, int l, int r) {
        if (l >= r) return;
        int x = nums[l], i = l - 1, j = r + 1;
        while (i < j) {
            do {
                i++;
            } while (nums[i] < x);
            do {
                j--;
            } while (nums[j] > x);
            if (i < j) {
                int temp = nums[i];
                nums[i] = nums[j];
                nums[j] = temp;
            }
        }
        quicksort(nums, l, j);
        quicksort(nums, j + 1, r);
    }
}
